package com.guaika.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.guaika.reggie.common.BaseContext;
import com.guaika.reggie.common.ResultMessage;
import com.guaika.reggie.entity.AddressBook;
import com.guaika.reggie.service.AddressBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author GuaiKa
 */
@Slf4j
@RestController
@RequestMapping("/addressBook")
@Api(tags = "地址相关接口")
public class AddressBookController {

    @Autowired
    private AddressBookService addressBookService;
    /**
     * 新增
     */
    @PostMapping
    @ApiOperation("新增地址接口")
    public ResultMessage<AddressBook> save(@RequestBody AddressBook addressBook) {
        return addressBookService.addressSave(addressBook);
    }


    /**
     * 设置默认地址
     */
    @PutMapping("default")
    @ApiOperation("设置默认地址接口")
    public ResultMessage<AddressBook> setDefault(@RequestBody AddressBook addressBook) {
        return addressBookService.addressSetDefault(addressBook);
    }


    /**
     * 根据id查询地址
     */
    @GetMapping("/{id}")
    @ApiOperation("根据Id查询地址接口")
    public ResultMessage get(@PathVariable Long id) {
        return addressBookService.addressGet(id);
    }


    /**
     * 查询默认地址
     */
    @GetMapping("default")
    @ApiOperation("查询默认地址")
    public ResultMessage<AddressBook> getDefault() {
        return addressBookService.addressGetDefault();
    }


    /**
     * 查询指定用户的全部地址
     */
    @GetMapping("/list")
    @ApiOperation("查询指定用户的全部地址")
    public ResultMessage<List<AddressBook>> list(AddressBook addressBook) {
        return addressBookService.addressList(addressBook);
    }

}
